package com.framework.loippi.envsupport;


public class EnvManager {

    public static UserEnvInfo getUserEnvInfo() {
        UserEnvInfo info = new UserEnvInfo(Thread.currentThread().getId() + "");
        Object clientIp = EnvContext.getThreadVar(EnvParam.CLIENT_IP.name());
        if (clientIp != null) {
            info.setClientIp((String) clientIp);
        }
        Object domain = EnvContext.getThreadVar(EnvParam.DOMAIN.name());
        if (domain != null) {
            info.setDomain((String) domain);
        }
        Object sessionId = EnvContext.getThreadVar(EnvParam.SESSION_ID.name());
        if (sessionId != null) {
            info.setSessionId((String) sessionId);
        }
        Object userAgent = EnvContext.getThreadVar(EnvParam.USER_AGENT.name());
        if (userAgent != null) {
            info.setUserAgent((String) userAgent);
        }
        Object token = EnvContext.getThreadVar(EnvParam.TOKEN.name());
        if (token != null) {
            info.setToken((String) token);
        }
        return info;
    }

    public static void putEnvParam(String key, Object value) {
        EnvContext.setThreadVar(key, value);
    }

}
